<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file daily_record.php */
/* Location: ./cashflow/controllers/daily_record.php */
class Daily_record extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('customers'); /** load table customers **/
        $this->load->model('gas'); /** load table Gas **/
        $this->load->module_model('billing-ar','invoices'); /** load table invoices **/
        if(!$this->session->userdata('username')) /** restrict area if not acces to login page**/
			redirect('/',301); 
    }
    
    function evc(){
        $this->ws->set('title',lang('evc'));/** title page Invoice Payment */
		$this->ws->set('username',$this->session->userdata('username')); /** username session */
		$this->ws->set('department',$this->session->userdata('dep')); /** departement session */
        /** if session already or no to view data **/
        if($this->session->userdata('evc_month')):
            $month =   $this->session->userdata('evc_month');
            $year  =   $this->session->userdata('evc_year');
            $cust  =   $this->session->userdata('evc_customer');
        else:
            $month =   '-';
            $year  =   '-';
            $cust  =   '-';
        endif;
        $this->ws->set('month',$month); /** variabel month from session **/
        $this->ws->set('year',$year); /** variabel year from session **/
        $this->ws->set('customer',$cust); /** variabel customer from session **/
        $this->ws->set('customers',$this->customers->getCustomerData()); /** Get Data Table Customers */
        $this->ws->set('head',$this->gas->getDailyCutOff($month,$year,$cust));
        $this->ws->set('evc',$this->gas->getDailyEvc($month,$year,$cust));/** Get Gas Daily EVC **/
        $this->ws->set_theme('smooth'); /** set theme to smooth **/
		$this->ws->view('daily-record/index_evc'); /** view layout to views/cash/index_payment **/
    }
    
    function getEVC(){
        /** array : insert value session from post **/
        $value  = array('evc_month'     => $this->input->post('month'),
                        'evc_year'      => $this->input->post('year'),
                        'evc_customer'  => $this->input->post('customer'));
        $this->session->set_userdata($value); /** set userdata value **/
        redirect('billing-ar/daily_record/evc',301); /** redirect to evc **/
    }
    
    function getEVCExport(){  
        /** if export via excel **/    
		if($this->input->post('export')=='excel')
            redirect('billing-ar/daily_record/getEVCExcel/'); 
        /** if export via pdf **/    
        elseif($this->input->post('export')=='pdf')    
            redirect('billing-ar/daily_record/getEVCPdf/');
        /** if export via email **/  
        elseif($this->input->post('export')=='email')    
            redirect('billing-ar/daily_record/getEVCEmail');
		else
			echo 'Error redirecting'; /** if error redirecting the page **/
    }
    
    function getEVCPdf(){
        /** Session Variabel **/
        $month =   $this->session->userdata('evc_month');
        $year  =   $this->session->userdata('evc_year');
        $cust  =   $this->session->userdata('evc_customer');
        /** go pdf **/
       	$pdf          =   $this->gas->getPdfEVC($month,$year,$cust); /** get Pdf EVC**/
        $value        =   file_get_contents($pdf); /** Read the file's contents **/
        $name         =   'EVC.pdf'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    function getEVCReset(){
        /** array : insert value session from post **/
        $value  = array('evc_month'     => 'evc_month',
                        'evc_year'      => 'evc_year',
                        'evc_customer'  => 'evc_customer');
        $this->session->unset_userdata($value); /** unset userdata value **/
        redirect('billing-ar/daily_record/evc',301); /** redirect to evc **/
     }
     
     function tpc(){
        $this->ws->set('title',lang('tpc'));/** title page */
		$this->ws->set('username',$this->session->userdata('username')); /** username session */
		$this->ws->set('department',$this->session->userdata('dep')); /** departement session */
        /** if session already or no to view data **/
        if($this->session->userdata('tpc_month')):
            $month =   $this->session->userdata('tpc_month');
            $year  =   $this->session->userdata('tpc_year');
            $cust  =   $this->session->userdata('tpc_customer');
        else:
            $month =   '-';
            $year  =   '-';
            $cust  =   '-';
        endif;
        $this->ws->set('month',$month); /** variabel month from session **/
        $this->ws->set('year',$year); /** variabel year from session **/
        $this->ws->set('customer',$cust); /** variabel customer from session **/
        $this->ws->set('customers',$this->customers->getCustomerData()); /** Get Data Table Customers */
        $this->ws->set('head',$this->gas->getDailyCutOff($month,$year,$cust));
        $this->ws->set('tpc',$this->gas->getDailyTpc($month,$year,$cust));/** Get Gas Daily Turbin **/
        $this->ws->set_theme('smooth'); /** set theme to smooth **/
		$this->ws->view('daily-record/index_tpc'); /** view layout to views/cash/index_tpc **/
    }
    
    function getTPC(){
        /** array : insert value session from post **/
        $value  = array('tpc_month'     => $this->input->post('month'),
                        'tpc_year'      => $this->input->post('year'),
                        'tpc_customer'  => $this->input->post('customer'));
        $this->session->set_userdata($value); /** set userdata value **/
        redirect('billing-ar/daily_record/tpc',301); /** redirect to evc **/
    }
    
    function getTPCExport(){  
        /** if export via excel **/    
		if($this->input->post('export')=='excel')
            redirect('billing-ar/daily_record/getTPCExcel/'); 
        /** if export via pdf **/    
        elseif($this->input->post('export')=='pdf')    
            redirect('billing-ar/daily_record/getTPCPdf/');
        /** if export via email **/  
        elseif($this->input->post('export')=='email')    
            redirect('billing-ar/daily_record/getTPCEmail');
		else
			echo 'Error redirecting'; /** if error redirecting the page **/
    }
    
    function getTPCPdf(){
        /** Session Variabel **/
        $month =   $this->session->userdata('tpc_month');
        $year  =   $this->session->userdata('tpc_year');
        $cust  =   $this->session->userdata('tpc_customer');
        /** go pdf **/
       	$pdf          =   $this->gas->getPdfTPC($month,$year,$cust); /** get Pdf TPC**/
        $value        =   file_get_contents($pdf); /** Read the file's contents **/
        $name         =   'TPC.pdf'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    function getTPCReset(){
        /** array : insert value session from post **/
        $value  = array('tpc_month'     => 'tpc_month',
                        'tpc_year'      => 'tpc_year',
                        'tpc_customer'  => 'tpc_customer');
        $this->session->unset_userdata($value); /** unset userdata value **/
        redirect('billing-ar/daily_record/tpc',301); /** redirect to tpc **/
    }
    
    function volume(){
        $this->ws->set('title',lang('volume'));/** title page */
		$this->ws->set('username',$this->session->userdata('username')); /** username session */
		$this->ws->set('department',$this->session->userdata('dep')); /** departement session */
        /** if session already or no to view data **/
        if($this->session->userdata('vol_month')):
            $month =   $this->session->userdata('vol_month');
            $year  =   $this->session->userdata('vol_year');
        else:
            $month =   '-';
            $year  =   '-';
        endif;
        $this->ws->set('month',$month); /** variabel month from session **/
        $this->ws->set('year',$year); /** variabel year from session **/
        $this->ws->set('custGroup',$this->customers->getAllCustomer('group')); /** Customer **/
        $this->ws->set('daily',$this->gas->getDailyEvc($month,$year,'','distinct'));
        $this->ws->set_theme('smooth'); /** set theme to smooth **/
		$this->ws->view('daily-record/index_volume'); /** view layout to views/cash/index_tpc **/
    }
    
    function getVolume(){
        /** array : insert value session from post **/
        $value  = array('vol_month'     => $this->input->post('month'),
                        'vol_year'      => $this->input->post('year'));
        $this->session->set_userdata($value); /** set userdata value **/
        redirect('billing-ar/daily_record/volume',301); /** redirect to evc **/
    }
    
    function getVolumeExport(){  
        /** if export via excel **/    
		if($this->input->post('export')=='excel')
            redirect('billing-ar/daily_record/getVolumeExcel/'); 
        /** if export via pdf **/    
        elseif($this->input->post('export')=='pdf')    
            redirect('billing-ar/daily_record/getVolumePdf/');
        /** if export via email **/  
        elseif($this->input->post('export')=='email')    
            redirect('billing-ar/daily_record/getVolumeEmail');
		else
			echo 'Error redirecting'; /** if error redirecting the page **/
    }
    
    function getVolumePdf(){
        /** Session Variabel **/
        $month =   $this->session->userdata('vol_month');
        $year  =   $this->session->userdata('vol_year');
        /** go pdf **/
       	$pdf          =   $this->gas->getPdfVolume($month,$year); /** get Pdf Volume **/
        $value        =   file_get_contents($pdf); /** Read the file's contents **/
        $name         =   'TPC.pdf'; /** file name content **/
        force_download($name,$value); /** download the file **/
    }
    
    function getVolumeReset(){
        /** array : insert value session from post **/
        $value  = array('vol_month'     => 'vol_month',
                        'vol_year'      => 'vol_year');
        $this->session->unset_userdata($value); /** unset userdata value **/
        redirect('billing-ar/daily_record/volume',301); /** redirect to evc **/
    }
    
 }